//
//  GuestureCell.m
//  QRMaster
//
//  Created by myApple on 15/6/27.
//  Copyright (c) 2015年 myApple. All rights reserved.
//

#import "GuestureCell.h"

@interface GuestureCell ()
{
    UILabel * titleNameLabel;
    UISwitch * guestureSwitch;
}

@end

@implementation GuestureCell

- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        // Initialization code
        [self prepareView];
    }
    return self;
}

-(void)prepareView
{
    float ScreenWidth = [UIScreen mainScreen].bounds.size.width;
    float x = 40;
    float y = 10;
    float width = ScreenWidth - x;
    float heigth = 20;
    
    titleNameLabel = [[UILabel alloc]initWithFrame:CGRectMake(x, y, width, heigth)];
    titleNameLabel.font = [UIFont systemFontOfSize:16.0];
    [self.contentView addSubview:titleNameLabel];
    
    guestureSwitch = [[UISwitch alloc]initWithFrame:CGRectMake(self.frame.size.width - 60, 10, 40, 30)];
    [guestureSwitch addTarget:self action:@selector(switchAction:) forControlEvents:UIControlEventTouchUpInside];
    [self.contentView addSubview: guestureSwitch];
}


-(void)switchAction:(UISwitch *)sender
{
    if (_delegate && [_delegate respondsToSelector:@selector(GuestureCellSender:)]) {
        [_delegate GuestureCellSender:sender];
    }
}

-(void)setTitleName:(NSString *)titleName
{
    _titleName = titleName;
    titleNameLabel.text = titleName;
}

-(void)setShowSwitch:(BOOL)showSwitch
{
    _showSwitch = showSwitch;
    if (_showSwitch) {
        guestureSwitch.on = YES;
    }
    else
    {
        guestureSwitch.on = NO;
    }
}



- (void)awakeFromNib {
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
